import React,{Component} from "react"
import "./index.css"
import qs from "qs"
class Login extends Component{
    constructor(props){
        super(props)
        this.state={
            uname:"",
            upwd:""
        }
    }
    for_submit(){
        var name=this.state.uname
        var pwd=this.state.upwd
        console.log(name,pwd)
        this.$axios.post("http://127.0.0.1/React/app/server/login.php",qs.stringify({name:name,pwd:pwd})).then(function(res){
            if(res.data.status==1){
                alert(res.data.msg)
            }
        })
    }
    uname_change(evt){
        var val=evt.target.value
        this.setState(state=>{
            state.uname=val
            return state
        })
    }
    upwd_change(evt){
        var val=evt.target.value
        this.setState(state=>{
            state.upwd=val
            return state
        })
    }
    render(){
        return (
           <div>
                <div className="login">
                   <p><input  type="text" placeholder="账号" onChange={evt=>{this.uname_change(evt)}} /></p>
                   <p><input  type="text" placeholder="请输入密码" onChange={evt=>{this.upwd_change(evt)}} /></p>
                   <p><input  type="submit" className="sub"  onClick={evt=>{this.for_submit()}}  value="立即注册"/></p>
                   <p> <a onClick={()=>{this.props.change_type(2)}}>没有账号？<i>立即注册</i></a></p>
                </div>
           </div>
        )
    }
} 
export  default Login